package com.company.OfferGuide;

public class 到n整数中1出现的次数 {


    public int countDigitOne(int n) {
        int count = 0;

        for (int i = 1; i <= n; i++) {
            count += countNum(i);
        }

        return count;
    }

    public int countNum(int n){
        int count = 0;
        while (n != 0) {
            if ((n % 10) == 1) {
                count++;
            }
            n = n /10;
        }

        return count;
    }


}
